﻿using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using VDataAdapter.BlockingQueue;
using System.Collections;
using System.Collections.Generic;
using VDataAdapter.ClientManagement;

namespace VDataAdapter.ClientServer
{
    public class VDataClientThread : ClientThread
    {
        protected static PSAdapterThread _psAdapter;
        protected static ManualResetEvent TerminatingExecutableEvent = new ManualResetEvent(false);
        protected bool _isSeq1;
        public bool IsReloadData;
        protected int currentSeq;

        public VDataClientThread(TcpClient clientSocket, CommunicationDataQueue qMain, ArrayList memHistories, PSAdapterThread psAdapthread)
            : base(clientSocket, qMain, memHistories)
        {
            IsReloadData = false;
        }

        public VDataClientThread(TcpClient clientSocket, CommunicationDataQueue qMain, ArrayList memHistories) : base(clientSocket, qMain, memHistories)
        {            
            IsReloadData = false;
        }

        //protected void StartPSAdapter()
        //{            
        //    PSAdapterThread psAdapater = new PSAdapterThread(TerminatingExecutableEvent, qMain);
        //    TerminatingExecutableEvent.Set();
        //}

        protected override void HandleResetSequence()
        {
            base.HandleResetSequence();
            IsReloadData = true;
        }

        protected override void HandleRecoverSequence()
        {
            base.HandleRecoverSequence();
            IsReloadData = true;
        }

        protected override void HandleMissingSequence(int seq)
        {
            base.HandleMissingSequence(seq);
        }

        //protected override void HandleSequence()
        //{
        //    //if (_psAdapter != null)
        //    //{
        //    //    _psAdapter.Unsubcribes();
        //    //    StartPSAdapter();
        //    //}
        //    //Thread thread = new Thread(new ThreadStart(StartPSAdapter));
        //    //thread.IsBackground = true;
        //    //thread.Start();
        //    Console.WriteLine("Reload Data because seq = 1");
        //    IsReloadData = true;
        //    // while (true) ;
        //    // base.ReloadData();            
        //}

        public override void Start()
        {
            // ReloadData();
            base.Start();
        }

        //public int Stop()
        //{
        //    _psAdapter.Unsubcribes();
        //    return base.Stop();
        //}
      
    }
}
